package com.sky.mapper;

import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    List<Category> page(CategoryPageQueryDTO categoryPageQueryDTO);

    @Update("update category set name = #{name}, sort = #{sort}, " +
            "update_time = #{updateTime} where id = #{id}")
    void update(Category category);

    @Update("update category set status = #{status}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    void enableSwitch(Category category);

    @Insert("insert into category (type, name, sort, status, " +
            "create_time, update_time, create_user, update_user) " +
            "values (#{type}, #{name}, #{sort}, #{status}, " +
            "#{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void addCategory(Category category);


    List<Category> selectByType(Integer type);

    @Select("select * from dish where category_id = #{id}")
    List<Dish> getById(Integer id);

    @Delete("delete from category where id = #{id}")
    void delete(Integer id);

    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> selectByCategoryId(Integer categoryId);

    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<DishItemVO> selectById(Integer id);
}
